from django.shortcuts import render
from django.shortcuts import HttpResponse

from .myforms import StudentForm
from .models import Students
# Create your views here.
# todo
def index(request):
    if request.method == "GET":
        form = StudentForm()
        return render(request, 'index.html',{"form":form})
    if request.method == "POST":
        form = StudentForm(request.POST)
        if form.is_valid():
            student = Students(**form.cleaned_data)
            student.save()
        else:
            return render(request, 'index.html', {"form": form})
        return HttpResponse("ok")
